require(['./config'],()=>{
    require(['template','jquery'],(template)=>{
        class zhuCe {
            constructor(){
                this.user()
            }
            user(){
                // 点击提交按钮获取name password 
                $('.tijiao').on('click',function(){
                    let name = $('.username').val()
                    let password = $('.password').val()
                    let userInfo = {name,password}
                   
                    // let userInfo = null
                    // console.log(userInfo)
                    // 先取出来判断是不是第一次注册
                    var userList = localStorage.getItem('userList')
                    // console.log(userList)
                    if(userList){
                        // 取到值就说明不是第一次存
                        userList = JSON.parse(userList)
                        // 判断用户名是否重复
                        let isExit = userList.some(user=>{
                            return user.name === name
                        })
                        // console.log(isExit)
                        if(isExit){
                            alert('注册失败，用户名重复')
                        }else{
                            userList.push(userInfo)
                            localStorage.setItem('userList',JSON.stringify(userList))
                            alert('注册成功，即将跳转登录页面')
                            location.href="/html/login.html"
                        }
                    }else{
                        if(name && password){
                            // console.log(999)
                            localStorage.setItem('userList',JSON.stringify([userInfo]))
                            alert('注册成功，即将跳转登录页面')
                            location.href="/html/login.html"
                        }else{
                            alert('请输入用户名密码注册')
                        }
                        // localStorage.setItem('userList',JSON.stringify([userInfo]))
                        // alert('注册成功，即将跳转登录页面')
                        // location.href="/html/login.html"
                    }
                    // console.log(userList)
                    
                })
            }
        }
        new zhuCe()
    })
})